local weishi = fk.CreateSkill{
    name = "xiaobai__weishi"
}
Fk:loadTranslationTable{
    ["xiaobai__weishi"] = "慰释",
    [":xiaobai__weishi"] = "与你距离为1以内的角色受到伤害后，你可以交给伤害来源一张手牌，伤害来源可改为令受伤角色获得，若其如此做，这些角色各摸一张牌。",
    ["#xiaobai__weishi-invoked"] = "是否发动 慰释，交给 %dest 一张手牌？",
    ["#xiaobai__weishi-choose"] = "慰释：%src 即将交给你一张牌手牌，是否改为令 %dest 获得？",
}

weishi:addEffect(fk.Damaged, {
    anim_type = "masochism",
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(weishi.name) and target:distanceTo(player) < 2 and target:isAlive() and data.from and data.from:isAlive() and not player:isKongcheng()
    end,
    on_cost = function (self, event, target, player, data)
        local cards = player.room:askToCards(player, {
            include_equip = false,
            pattern = ".",
            skill_name = weishi.name,
            max_num = 1,
            min_num = 1,
            prompt = "#xiaobai__weishi-invoked::"..data.from.id
        })
        if #cards > 0 then
            event:setCostData(self, {cards = cards})
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local cards = event:getCostData(self).cards
        if room:askToSkillInvoke(data.from, {
            skill_name = weishi.name,
            prompt = "#xiaobai__weishi-choose:"..player.id..":"..target.id
        }) then
            room:obtainCard(target, cards, false, fk.ReasonGive, player, weishi.name)
            local tos = {}
            table.insertTableIfNeed(tos, {data.from.id, player.id, target.id})
            for _, id in ipairs(tos) do
                local tp = room:getPlayerById(id)
                if not tp.dead then
                    tp:drawCards(1, weishi.name)
                end
            end
        else
            room:obtainCard(data.from, cards, false, fk.ReasonGive, player, weishi.name)
        end
    end,
})

return weishi